package action;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import entity.Student;
import service.StudentService;

@Controller
@RequestMapping("/student")
public class StudentAction {
	
	
	@Autowired
	private StudentService studentService;
	
	@RequestMapping("loginView")
	protected String loginView() {
		return "/student/login";
	}
	@RequestMapping("login")
	protected String login(Model model,Student student,HttpSession session) {
		if(studentService.login(student, session)!=null) {
			return "redirect:/student/subject/list.do";
		}else {
			model.addAttribute("info", "账号密码错误");
			return "/student/login";
		}
	}
	@RequestMapping("subject/list.do")
	protected String subjectList(Model model,HttpSession session) {
		model.addAttribute("teacherSubjects", studentService.findTeacherSubjectByClasses(session));
		return "/student/subject_list";
	}
	@RequestMapping("subject/score/list.do")
	protected String scoreList(Model model,HttpSession session,String id) {
		model.addAttribute("scores", studentService.findScoreByStudentAndSubject(session, id));
		return "/student/score_list";
	}
	
}
